<%-- 
    Document   : request_cuentas
    Created on : 7/10/2011, 03:42:19 PM
    Author     : Jose
--%>

<%@ page import="PaquetesJL.*" %>
<%@page import="java.sql.ResultSet" %>

<%
    int idcuenta=Integer.parseInt(request.getParameter("idcuenta"));        
    
    String sqlServer = pageContext.getServletContext().getInitParameter("sqlServer");
    String databaseName = pageContext.getServletContext().getInitParameter("databaseName");
    String userName = pageContext.getServletContext().getInitParameter("userName");
    String PasswordP = pageContext.getServletContext().getInitParameter("password");
    String Backup = pageContext.getServletContext().getInitParameter("RutaBackup");
    
    byte[] decodedBytes = ConexionBD.decode(PasswordP);
    String decodedPassword = new String(decodedBytes).trim();
    
    ConexionBD Conexion = new ConexionBD(sqlServer, databaseName, userName, decodedPassword, Backup);
    Conexion.IniciarConexion();
    ResultSet r=Conexion.EjecutarConsulta("EXEC dbo.ConsultarSaldo "+idcuenta);                           
    boolean error=false;
    String tipocuenta="";
    float sincompensar=-1,saldo=-1;
    String imprimir=
            "<label>Propietarios de la Cuenta</label>"
            + "<br>"
            + "<table border=\"1\">"
            + "<thead>"
            + "<tr>"
            + "<th>Codigo de Cliente</th>"
            + "<th>Nombre</th>"
            + "<th>Apellido</th>"
            + "<th>Cedula</th>"
            + "<th>Tipo de Cliente</th>"
            + "</tr>"
            + "</thead>"
            + "<tbody>";
    while(r.next() && !error){
        if(r.getInt(1)<0){
            error=true;
            out.print(r.getString(2));
        }
        if(!error){
            tipocuenta=r.getString(2);
            sincompensar=r.getFloat(8);
            saldo=r.getFloat(9);
            
            imprimir+="<tr>"
                    + "<td>"+r.getInt(3) +"</td>"
                    + "<td>"+r.getString(4)+"</td>"
                    + "<td>"+r.getString(5)+"</td>"
                    + "<td>"+r.getString(6)+"</td>"
                    + "<td>"+r.getString(7)+"</td>"
                    + "</tr>";
        }
    }   
    
    if(!error){
        imprimir+="</tbody>"
                + "</table>"
                + "<br>"
                + "<label>Tipo de Cuenta:</label>"+tipocuenta
                + "<br>"
                + "<label>Saldo:</label>Q"+saldo
                + "<br>"
                + "<label>Reserva:</label>Q"+sincompensar
                + "<br>";
        out.print(imprimir);
    }
    Conexion.CerrarConexion();        
    
    
%>
